package cn.hospital.controller;

import cn.hospital.entity.Chart;
import cn.hospital.service.ChartService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/main")
public class mainController {
    @Resource
    private ChartService chartService;

    /**
     * 根据时间查询（一年中能够每一个月患者数量比对）
     * @param timeMonth
     * @return
     */
    @RequestMapping("/findByTime")
    @ResponseBody
    public Map<String,Object> findByTime(String timeMonth){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        if(timeMonth==""){
            timeMonth = sdf.format( new Date());
        }else{
            timeMonth = timeMonth.substring(0,4);
        }
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("chartList",chartService.findByTime(timeMonth));
        return map;
    }

    /**
     * 根据时间查询（一年中能够每一个月随访组数量比对）
     * @param timeMonth
     * @return
     */
    @RequestMapping("/findByCreatorTime")
    @ResponseBody
    public Map<String,Object> findByCreatorTime(String timeMonth){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        if(timeMonth==""){
            timeMonth = sdf.format( new Date());
        }else{
            timeMonth = timeMonth.substring(0,4);
        }
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("chartList",chartService.findByCreatorTime(timeMonth));
        return map;
    }
}
